Private fso As Scripting.FileSystemObject
Private prefsFile As Scripting.TextStream

Public Function getPref(relativePath As String, preference As String)
    
    On Error Resume Next
    
    If relativePath <> "" Then relativePath = "\" & relativePath
    With New regOp
        .Root = HKEY_LOCAL_MACHINE
        .Key = "Software\bbd\AccessSearch\preferences" & relativePath
        getPref = .Value(preference)
    End With
    
End Function

Public Function setPref(relativePath As String, preference As String, Value As Variant)
    
    On Error Resume Next
    
    If relativePath <> "" Then relativePath = "\" & relativePath
    
    With New regOp
        .Root = HKEY_LOCAL_MACHINE
        .Key = "Software\bbd\AccessSearch\preferences" & relativePath
        .Value(preference) = Value
    End With

End Function

Public Function saveColumnWidths()
    
    On Error Resume Next
    
    strColumnWidths = ""
    i = 0
    For Each header In FRMmain.DataGrid.Columns
        i = i + 1
        strColumnWidths = strColumnWidths & header.Width & ","
    Next
    If i > 0 Then
        strColumnWidths = Left(strColumnWidths, Len(strColumnWidths) - 1)
        setPref "", "columnWidths", strColumnWidths
        DLGpreferences.Hide
    Else
        MsgBox "There Are Currently No Columns" & vbCrLf & "You Must First Open A Database File"
    End If
End Function


Public Sub setDefaultPrefs()
    
    On Error Resume Next
    
    With New regOp
    
        .Root = HKEY_LOCAL_MACHINE
        .Key = "Software\bbd\AccessSearch"
        
        If .Value("version") <> "4.2" Then
            .Value("version") = "4.2"
            .Key = "Software\bbd\AccessSearch\preferences"
            .Value("columnWidths") = ""
            .Value("defaultDatabasePath") = App.Path & "\localStock.mdb"
            .Value("defaultSearchField") = "partNumber"
            .Key = "Software\bbd\AccessSearch\preferences\remoteDB"
            .Value("autoUpdate") = 1
            .Value("fieldNames") = "partNumber,quantity,remark,manufacturer,dateCode,userComment"
            .Value("serverAddress") = "example : http://SERVER_ADDRESS"
            .Value("updatePagePath") = "example : FOLDER(s)/PAGE_NAME"
            .Value("databaseName") = "webStock.mdb"
        End If
        
    End With
End Sub
'----------------
'   NOT USED    '
'----------------
'Public Function getPreference(fileName As String, preference As String)
'    Set fso = New Scripting.FileSystemObject
'
'    prefsFilePath = App.Path & "\preferences\" & fileName
'
'    If Not fso.FolderExists(App.Path & "\preferences") Then
'        MsgBox "An error occured while trying to load a preference" & vbCrLf & _
'            "There is no ""preferences"" folder in the application directory"
'        Exit Function
'    End If
'
'    If Not fso.FileExists(prefsFilePath) Then
'        MsgBox "An error occured while trying to load a preference" & vbCrLf & _
'            "The preference file """ & fileName & """ was not found"
'        Exit Function
'    End If
'
'    Set prefsFile = fso.OpenTextFile(prefsFilePath, ForReading, False)
'
'    Do Until prefsFile.AtEndOfStream
'        line = Trim(prefsFile.ReadLine)
'        If Not Left(line, 2) = "//" Then
'            equalSignPosition = InStr(line, "=")
'            prefName = Left(line, equalSignPosition - 1)
'            If preference = prefName Then
'                prefValue = Mid(line, equalSignPosition + 1)
'                getPreference = prefValue
'            End If
'        End If
'    Loop
'
'End Function
